home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / grafik / seepcx / seepcxhd.c next >
Encoding:
C/C++ Source or Header  |  1990-11-01  |  5.7 KB  |  215 lines

  1. /* seepcxhd.c                   31 oct 1990
  2.  
  3.   - seepcxhd displays a pcx file header
  4.   - this is a first version, it could probably use some improvement
  5.   - in particular, values it prints for Palette info, Hscreensize,
  6.     and Vscreensize are suspect
  7.   - written by Art D'Adamo, CompuServe 72371,1673
  8.   - complied using QuickC 2.5
  9.   - released into the public domain
  10.  
  11. */
  12.  
  13. #define HDR_LEN 128
  14.  
  15. static int load_int( char a[] ), pause_ec( int a );
  16.  
  17. #include <stdio.h>
  18. #include <fcntl.h>
  19. #include <sys\types.h>
  20. #include <sys\stat.h>
  21. #include <io.h>
  22. #include <conio.h>
  23.  
  24. char buf[1000], ibuf[2];
  25. char red[256], green[256], blue[256];
  26. int version;
  27. union {
  28.     char a;
  29.     unsigned int b;
  30. } x;
  31. unsigned int ir, ig, ib;
  32. long flen, pos, offset;
  33.  
  34.  
  35. /* ------------------------------------------------------------- */
  36. main( argc, argv )
  37. int argc;
  38. char *argv[];
  39. {
  40. int i, k, fh, color, egavga;
  41.  
  42.     /* check input */
  43.     if( argc < 2 ) {
  44.     printf("\tUsage:    seepcxhd (PCX_image_file_name)");
  45.     printf("\n\tExample:  seepcxhd abc.pcx");
  46.     exit( 1 );
  47.     }
  48.  
  49.  
  50.     /* get the PCX file size */
  51.     if( (fh = open( argv[1], O_RDONLY | O_BINARY)) != -1 ) {
  52.     flen = filelength( fh );
  53.     printf("PCX image file %s is %ld bytes long ", argv[1], flen );
  54.     }
  55.     else {
  56.     printf("\nseepcxhd can't open %s. Must exit.", argv[1] );
  57.     exit(1);
  58.     }
  59.  
  60.     /* read PCX header */
  61.     i = read (fh, buf, HDR_LEN);
  62.     if (i != HDR_LEN ) {
  63.     printf ("\n(image header) i %d, HDR_LEN %d", i, HDR_LEN);
  64.     printf ("\nread error");
  65.     exit( 1 );
  66.     }
  67.  
  68.     /* show PCX header ------------------------------------------- */
  69.     printf("\n%hd\tManufacturer code", buf[0]);
  70.  
  71.     version = (int) buf[1];
  72.     printf("\n %hd\tVersion", version);
  73.     if( version == 0 )
  74.     printf(" - Version 2.5 of PC Paintbrush");
  75.     else if( version == 2 )
  76.     printf(" - Version 2.8 w/palette info");
  77.     else if( version == 3 )
  78.     printf(" - Version 2.8 w/o palette info");
  79.     else if( version == 4 )
  80.     printf(" - PC Paintbrush for Windows & Windows Ver 5");
  81.     else if( version == 5 )
  82.     printf(" - Win Ver 3.0 & Paintbrush & Publisher's PB");
  83.     else printf(" - Unknown Version");
  84.  
  85.     i = (int) buf[2];
  86.     printf("\n %hd\tEncoding", i);
  87.     if( i == 0 ) printf(" - No Encoding");
  88.     else if( i == 1 ) printf(" - .PCX run length encoding");
  89.     else printf(" - Unknown Encoding");
  90.  
  91.     i = (int) buf[3];
  92.     printf("\n %hd\tBits per Pixel per Plane", i);
  93.  
  94.     i = load_int( &(buf[4]) );   printf("\nWindow:\txmin: %3hd", i);
  95.     i = load_int( &(buf[6]) );   printf("\tymin: %3hd", i);
  96.     i = load_int( &(buf[8]) );   printf("\n\txmax: %3hd", i);
  97.     i = load_int( &(buf[10]) );  printf("\tymax: %3hd", i);
  98.  
  99.     i = load_int( &(buf[12]) );
  100.     printf("\n %hd\tHor. Res. in DPI", i);
  101.  
  102.     i = load_int( &(buf[14]) );
  103.     printf("\n %hd\tVer. Res. in DPI", i);
  104.  
  105.     /* read & save EGA color map */
  106.     i = 16;
  107.     for( color = 0; color < 16; color++) {
  108.     red[color] = buf[i++];
  109.     green[color] = buf[i++];
  110.     blue[color] = buf[i++];
  111.     }
  112.  
  113.     printf("\n %hd\tNPlanes", buf[65] );
  114.  
  115.     i = load_int( &(buf[66]) );
  116.     printf("\n %hd\tBytes per Line", i);
  117.  
  118.     i = load_int( &(buf[68]) );
  119.     printf("\n %hd\tPalette info", i);
  120.  
  121.     i = load_int( &(buf[70]) );
  122.     printf("\n %hd\tHscreensize", i);
  123.  
  124.     i = load_int( &(buf[72]) );
  125.     printf("\n %hd\tVscreensize", i);
  126.  
  127.  
  128.     /* Determine if EGA or VGA color map */
  129.     offset = (long) flen-769;
  130.     pos = lseek( fh, offset, SEEK_SET );
  131.     if( pos == -1L ) {
  132.     perror( "\nlseek failed" );
  133.     printf("\nflen %d, offset %ld, pos %ld", flen, offset, pos);
  134.     exit( 1 );
  135.     }
  136.     i = read (fh, buf, 769);
  137.     if (i != 769 ) {
  138.     printf ("\nread error (769), i %d", i);
  139.     exit( 1 );
  140.     }
  141.     egavga = buf[0];
  142.  
  143.     /* print out color map? */
  144.     if( egavga != 12 ) printf("\n\nShow EGA color map? (y/n) > ");
  145.     else printf("\n\nShow VGA color map? (y/n) > ");
  146.     i = getche();
  147.     if( i != 'y' && i != 'Y') return 0;
  148.  
  149.     /* print out color map */
  150.     if( egavga != 12 ) {
  151.     /* print EGA color map */
  152.     printf("\n\n\tEGA Color Map\nColor\t  Red\tGreen\t Blue");
  153.     for( color = 0; color < 16; color++) {
  154.         x.a = red[color];   ir = x.b;
  155.         x.a = green[color];   ig = x.b;
  156.         x.a = blue[color];   ib = x.b;
  157.         printf("\n  %u\t  %d\t  %u\t  %u", color, ir, ig, ib);
  158.     }
  159.     }
  160.     else {
  161.     /* print VGA color map */
  162.     printf("\n\n\t\tVGA Color Map\t(Color, Red, Green, Blue)");
  163.     i = 1;
  164.     for( color = 0; color < 256; color +=4) {
  165.         x.a = buf[i++];   ir = x.b;
  166.         x.a = buf[i++];   ig = x.b;
  167.         x.a = buf[i++];   ib = x.b;
  168.         printf("\n(%3u,%3u,%3u,%3u)", color, ir, ig, ib);
  169.         x.a = buf[i++];   ir = x.b;
  170.         x.a = buf[i++];   ig = x.b;
  171.         x.a = buf[i++];   ib = x.b;
  172.         printf("  (%3u,%3u,%3u,%3u)", color+1, ir, ig, ib);
  173.         x.a = buf[i++];   ir = x.b;
  174.         x.a = buf[i++];   ig = x.b;
  175.         x.a = buf[i++];   ib = x.b;
  176.         printf("  (%3u,%3u,%3u,%3u)", color+2, ir, ig, ib);
  177.         x.a = buf[i++];   ir = x.b;
  178.         x.a = buf[i++];   ig = x.b;
  179.         x.a = buf[i++];   ib = x.b;
  180.         printf("  (%3u,%3u,%3u,%3u)", color+3, ir, ig, ib);
  181.         if( color > 0 && color%88 == 0 ) pause_ec( 1 );
  182.     }
  183.     }
  184.  
  185.     close( fh );
  186.     return 0;
  187. }
  188.  
  189.  
  190. /* -------------------------------------------------- */
  191. static int load_int( cbuf )
  192. char cbuf[];
  193. {
  194.     union {
  195.     int       s_int;
  196.     char            s_chr[2];
  197.     } s_un;
  198.  
  199.     s_un.s_chr[0] = cbuf[0];
  200.     s_un.s_chr[1] = cbuf[1];
  201.     return s_un.s_int;
  202.  
  203. }
  204.  
  205. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  206. static int pause_ec( int flag )
  207. {
  208. int ch;
  209. fflush( stdin );
  210. if( flag > 0 ) printf("\n\tPress any key to continue > ");
  211. ch = getch();
  212. return 0;
  213. }
  214.  
  215.